//
//  OrderAPI.m
//  RainbowFM
//
//  Created by chenli on 14/12/29.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "OrderAPI.h"
#import "AFAppDotNetAPIClient.h"

@implementation OrderAPI

-(void)createOrderWithUserID:(NSString *)userId ProdID:(NSString *)prodId prodPrice:(NSString *)prodPrice_ prodName:(NSString *)prodName prodImg:(NSString *)prodImage prodNum:(NSString *)prodNum buyerName:(NSString *)buyerName_ buyerPhone:(NSString *)phone buyerAddr:(NSString *)address result:(void (^)(NSString *))res{
    
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_create_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"prodId" : prodId,
                                                              @"prodPrice" : prodPrice_,
                                                              @"prodName" : prodName,
                                                              @"prodImg" : prodImage,
                                                              @"prodNum" : prodNum,
                                                              @"buyerName" : buyerName_,
                                                              @"buyerPhone" : phone,
                                                              @"buyerAddr" : address}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"orderId"]);
                                          }
                                          else{
                                              res(nil);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil);
                                      }];
    
}

-(void)fetchUserOrderListWithUserID:(NSString *)userId orderStatus:(NSString *)status cancel:(NSString *)cancel_ merchantID:(NSString *)merchantId pageSize:(NSString *)count currentPage:(NSString *)start result:(void (^)(NSArray *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_list_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"cancel" : cancel_,
                                                              @"orderStatus" : status,
                                                              @"pageSize" : count,
                                                              @"currentPage" : start}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"");
                                      }];
}


-(void)fetchOrderDetailWithUserID:(NSString *)userId orderID:(NSString *)orderId result:(void(^) (NSDictionary *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_view_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"");
                                      }];
}


-(void)cancelOrderWithUserID:(NSString *)userId orderID:(NSString *)orderId result:(void(^) (BOOL, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_cancel_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,@"");
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"");
                                      }];
}


-(void)orderRemindWithUserID:(NSString *)userId orderID:(NSString *)orderId result:(void(^) (BOOL, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_remind_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,@"");
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"");
                                      }];
}


-(void)receiptOrderWithUserID:(NSString *)userId orderID:(NSString *)orderId result:(void(^) (BOOL, NSString *))res{

    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_receipt_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,@"");
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"");
                                      }];
}


-(void)delayOrderWithUserID:(NSString *)userId orderID:(NSString *)orderId result:(void(^) (BOOL, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_delay_receipt_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,@"");
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"");
                                      }];
}


-(void)refundOrderWithUserID:(NSString *)userId orderID:(NSString *)orderId desc:(NSString *)des result:(void(^) (BOOL, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_refund_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId,
                                                              @"desc" : des}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,@"");
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"");
                                      }];
}


-(void)returnOrderWithUserID:(NSString *)userId orderID:(NSString *)orderId logisName:(NSString *)logisName_ logisNum:(NSString *)logisNum result:(void(^) (BOOL, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_return_goods_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId,
                                                              @"logisName" : logisName_,
                                                              @"logisNum" : logisNum}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,@"");
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"");
                                      }];
}

-(void)confirmRefundOrderWithUserID:(NSString *)userId orderID:(NSString *)orderId desc:(NSString *)des result:(void (^)(BOOL, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_confirm_refund_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId,
                                                              @"desc" : des}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(YES,@"");
                                          }
                                          else{
                                              res(NO,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(NO,@"");
                                      }];
}


-(void)payTypeListWithUserID:(NSString *)userId orderID:(NSString *)orderId result:(void(^) (NSArray *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_pay_type_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"");
                                      }];
}


-(void)paymentWithUserID:(NSString *)userId orderID:(NSString *)orderId payType:(NSString *)type result:(void(^)(NSString *, NSString *))res{
    [[AFAppDotNetAPIClient sharedClient] POST:OMS_BASE_URL
                                   parameters:@{@"serviceName" : @"order_payment_req",
                                                @"callType" : @"002",
                                                @"params" : @{@"userId" : userId,
                                                              @"orderId" : orderId,
                                                              @"payType" : type}}
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"url"],@"");
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"");
                                      }];
    
}

@end
